/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package base;

import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author diego
 */
public class JGrafo {
    public ArrayList<Vertice> vertices;
    public HashMap<Vertice, ArrayList<Vertice>> adjacencies;
    

    public JGrafo(ArrayList<Vertice> vertices) {
        this.vertices = vertices;
        this.adjacencies = new HashMap<>(vertices.size());
        for (Vertice v : vertices) {
            this.adjacencies.put(v, new ArrayList<Vertice>());
        }
    }
    
    public void add_edge(Vertice v1, Vertice v2) {
        this.adjacencies.get(v1).add(v2);
    }
    
    public boolean delEdge(Vertice v1, Vertice v2) {
        try {
            return this.adjacencies.get(v1).remove(v2);
        } catch (Exception E) {
            return false;
        }
    }
    
    public boolean hasEdge(Vertice v1, Vertice v2) {
        try {
            return this.adjacencies.get(v1).contains(v2);
        } catch (Exception E) {
            return false;
        }
    }
    
    public ArrayList<Vertice> adjacencies (Vertice v1) {
        return this.adjacencies.get(v1);
    }
}
